home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / Show&Edit_1.8 / ARexx / Show&Edit.dopus5 next >
Text File  |  1997-06-05  |  9KB  |  366 lines

  1. /* $VER: Show&Edit.dopus5 1.8 (22.12.96) Frederic Steinfels
  2. */
  3.  
  4. /* History:
  5.  
  6.    ...
  7.  
  8.    1.0  Added the BACKGROUND mode (opening a new lister
  9.            not to make the current source busy)
  10.  
  11.    1.1    Added the progress bar.
  12.    
  13.    1.2    Switched from 'lister newprogress' to 'dopus progress'
  14.            as 'dopus progress' does not make the lister busy.
  15.            WHY IS 'DOPUS PROGRESS' NOT MENTIONED IN THE 5.5
  16.            MANUAL?
  17.  
  18.    1.3    Implemented workaround to get the selected entries for
  19.            both modes (name and icon action). This was necessary
  20.            as Dopus doesn't handle rexx commands concerning the
  21.            icon mode.  :-(  :-(
  22.         (Before starting the script, all selected entries
  23.          are written to a temporary file. This program does no
  24.          longer query the selected entries from Arexx, what was,
  25.          of course, a faster and better way...)
  26.          
  27.    1.4    Found a better solution. Another Arexx script gets all
  28.            the Selected Icons (first) and selects the corresponding
  29.            entries in the name mode so that the main script just has
  30.            to query them.
  31.  
  32.    1.5    Added numeric count (two lines ;-), Opus is cool )
  33.    
  34.    1.6    Forgot to delete a temporary file.
  35.  
  36.    1.7    Files that included spaces couldn't be opened. Unfortunately
  37.            some other special characters could also not work. This
  38.            only happens as I had to use the following workaround:
  39.  
  40.    1.8    Switched from SHOWEDIT{Qp}{ou} to SHOWEDIT{Qp}{Ql} and
  41.         it's also possible to create the file only once.
  42.         Before this wasn't possible due to a bug in Dopus 5.5.
  43.  
  44.  
  45.            This script is usign this line:
  46.  
  47.         command WAIT source handle dest handle User4 file
  48.         
  49.         This makes the lister with the selected handle executing
  50.         the 'User4' command on the file that is contained in
  51.         the variable 'file'. As you can start this script
  52.         in SHOW/EDIT, ASYNCHRONOUS/SYNCHRONOUS mode, all four 
  53.         user commands were needed if I didn't use a trick:
  54.         The first line of every User4 filetype command has
  55.         the line:
  56.         
  57.         Script: "T:SHOWEDIT{Qp}{Ql}"
  58.         
  59.         The {Qp} and {ou} flags are needed as you can start this
  60.         script several times in different modes and the name of this
  61.         'T:' file must be unique. The file itself contains the
  62.         following lines:
  63.  
  64.         set SHOW "RUN <>NIL: "
  65.         set EDIT "NOP "
  66.         alias SHOW "GET SHOW"
  67.         alias EDIT "GET EDIT"
  68.  
  69.         That's the file if you selected the SHOW button in ASYNC
  70.         mode. If you select the EDIT button in SYNC mode, the file
  71.         contains the following lines:
  72.  
  73.         set SHOW ""
  74.         set EDIT "NOP "
  75.         alias SHOW "GET SHOW"
  76.         alias EDIT "GET EDIT"
  77.  
  78.         and so on. ('NOP' is a program that does nothing. It's again
  79.         a workaround as the ';' does not work under these
  80.         circumstances. (If you don't believe it, try this:
  81.         set bla ";echo" [ENTER]    $bla [ENTER]))
  82.         
  83.         The lines that start the show/edit program look like this:
  84.         AmigaDOS: `SHOW`something
  85.         AmigaDOS: `EDIT`anotherprogram
  86.         
  87.         As I can't use `GET SHOW` directly (it contains a blank
  88.         what is illegal) I have to use a alias. This makes
  89.         it possible to select the mode a file gets started.
  90.         
  91.         I hope you understand now that it is important that the
  92.         file T:SHOWEDIT is unique. Otherwise the programs would
  93.         be started in the wrong way if you used this script several
  94.         times at once in different modes.
  95. */
  96.  
  97. /*
  98.    Unfortunately I had to use some 'workarounds' in this script
  99.    due to some missing features or bugs. You could say the whole
  100.    script is a work-around but with some additional features.
  101.    Dopus is only able to do the 'UserX' command (action set in
  102.    the filetype) on files in the current directory. It does not
  103.    scan for subdirectories even if you selected 'Recursive Dirs'.
  104.    You would have to define in the directory file type for 'UserX'
  105.    some commands that create a script that scans this subdir
  106.    and does 'UserX' on all entries. This is slow and ugly (how
  107.    to name and delete these temporary files???) so I decided
  108.    to do my own rexx script with all these cool features like:
  109.    - starting all files in a row
  110.    - starting all files at "once" (ASYNC)
  111.    - starting all files at "once" in the Background (from
  112.      another lister so that your lister won't be busy.
  113.      Unfortunately dopus can't open a lister invisible; I
  114.      have to open and THEN hide it)
  115. */
  116.  
  117. /*    BTW: Do not use the MacSound or MacSnd Datatype (filetype scan
  118.     could take some minutes per file). Use a version of the 
  119.     be.datatype that does not take executables for images and
  120.     crash. I think that the SoundModule filetype (delivered
  121.     by Opus5.5) does not work and that it has some ugly side
  122.     effects like ArcHandler crashing while doubleclicking on
  123.     a directory in name mode in an lha archive.
  124. */
  125.  
  126.  
  127. /*    The following files are required:
  128.  
  129.   · rexxdossupport.library
  130.     Copyright (C) 1994-1997 by Hartmut Goebel, <hartmut@oberon.nbg.sub.org>
  131.   · rexxtricks.library
  132.     Copyright (C) 1994,95 by Jürgen Kohrmeyer, <J_Kohrmeyer@wilam.north.de> 
  133.   · DosInfo
  134.     Copyright (C) 1992 by Christian A. Weber, <chris@limmat.ch>
  135.   · Show&Edit.dopus5
  136.     Frédéric Steinfels (fsteinfe@iiic.ethz.ch)
  137.   · Nop
  138.     Frédéric Steinfels (fsteinfe@iiic.ethz.ch)
  139. */
  140.  
  141. signal on BREAK_C
  142. signal on BREAK_D
  143. signal on BREAK_E
  144. signal on BREAK_F
  145. signal on HALT
  146. signal on IOERR
  147. signal on SYNTAX
  148. options failat 21
  149. options results
  150. parse arg arguments
  151.  
  152. Call Init
  153. address value PORT
  154.  
  155. Call CheckEntries
  156. Call QueryLister
  157. if BACKGROUND=1 then Call OpenInBG
  158. if dirs.count>0 then Call ScanSubDirs
  159. Call ExecFiles
  160. Call CleanUP
  161. Exit
  162.  
  163.  
  164. Unselect:
  165. if POS('/',files.cnt) ~= 0 then do
  166.     parse var files.cnt cpath "/" .
  167.     if cpath ~= lpath & symbol('lpath')='VAR' then do
  168.         lister select handle '"' || lpath || '"' 0
  169.         lister refresh handle full
  170.     end
  171.     lpath=cpath
  172. end
  173. else do
  174.     lister 'select' handle '"' || files.cnt || '"' 'off'
  175.     lister refresh handle full
  176. end
  177. return
  178.  
  179.  
  180.  
  181. Init:
  182. libname = "rexxdossupport.library"
  183. if ~show("L", libname) then do
  184.   if ~addlib(libname, 0, -30, 2) then do
  185.     say libname "not added!"
  186.     exit
  187.   end
  188. end
  189.  
  190. libname = "rexxtricks.library"
  191. if ~show("L", libname) then do
  192.   if ~addlib(libname, 0, -30) then do
  193.     say libname "not added!"
  194.     exit
  195.   end
  196. end
  197.  
  198. libname = "rexxsupport.library"
  199. if ~show("L", libname) then do
  200.   if ~addlib(libname, 0, -30) then do
  201.     say libname "not added!"
  202.     exit
  203.   end
  204. end
  205.  
  206. ProgramName = "Show&Edit.dopus5";
  207. ArgsTemplate = "PORT/A,HANDLE/A,ASYNC/S,EDIT/S,BACKGROUND/S"
  208. lf='0a'x
  209.  
  210. if strip(arguments) = '?' then do
  211.     call writech(STDOUT, ArgsTemplate || ': ')
  212. pull arguments
  213. end; else nop
  214. if ~ReadArgs(arguments,ArgsTemplate) then do
  215.     say Fault(RC,ProgramName)
  216.      exit 10
  217. end; else nop
  218. drop arguments
  219. return
  220.  
  221.  
  222.  
  223. CheckEntries:
  224. lister query handle numselentries
  225. if result=0 then exit
  226. return
  227.  
  228.  
  229.  
  230. QueryLister:
  231. lister query handle 'path'
  232. path = result
  233. lister query handle selfiles stem files
  234. if symbol('files.count') = 'LIT' then files.count=0
  235. lister query handle seldirs stem dirs
  236. if symbol('dirs.count') = 'LIT' then dirs.count=0
  237. return
  238.  
  239.  
  240.  
  241. OpenInBG:
  242. Command source handle dest handle wait NONE
  243. lister query handle position
  244. parse var result x "/" y "/" w "/" h " " .
  245. lister new x || "/" || y || "/" || w || "/" || h path
  246. HANDLE=result
  247. lister set handle visible 0
  248. return
  249.  
  250.  
  251.  
  252. ScanSubDirs:
  253. cnt=0
  254. if dirs.count > 0 then do
  255.     tmpfile='T:'||handle||RAND(10000000,99999999)
  256.     rv=delete(tmpfile)
  257.     do until cnt = dirs.count
  258.         address command 'cd "' || path || '"' || lf || 'C:list >>"' || tmpfile || '" "' || dirs.cnt || '" ALL FILES SORT NAME LFORMAT "%p%n"'
  259.         cnt=cnt+1
  260.     end
  261.     if open('tmp',tmpfile,'READ') then do
  262.         cnt=files.count
  263.         do until EOF('tmp')
  264.             files.cnt = readln('tmp')
  265.             cnt=cnt+1
  266.         end
  267.         files.count=cnt-1
  268.         rv=close('tmp')
  269.         rv=delete(tmpfile)
  270.     end
  271. end
  272. return
  273.  
  274.  
  275.  
  276. ExecFiles:
  277. address value port
  278. cnt = 0
  279.  
  280. if open('SE','T:SHOWEDIT'||PORT||HANDLE,'WRITE') then do
  281.     IF ASYNC=1 then do
  282.         IF EDIT=1 then do
  283.             rv=writeln('SE','set SHOW "NOP "')
  284.             rv=writeln('SE','set EDIT "RUN <>NIL: "')
  285.          end
  286.         else do
  287.             rv=writeln('SE','set SHOW "RUN <>NIL: "')
  288.             rv=writeln('SE','set EDIT "NOP "')
  289.         end
  290.     end
  291.     else do
  292.         IF EDIT=1 then do
  293.             rv=writeln('SE','set SHOW "NOP "')
  294.             rv=writeln('SE','set EDIT ""')
  295.         end
  296.         else do
  297.             rv=writeln('SE','set SHOW ""')
  298.             rv=writeln('SE','set EDIT "NOP "')
  299.         end
  300.     end
  301.     rv=writeln('SE','alias SHOW "GET SHOW"')
  302.     rv=writeln('SE','alias EDIT "GET EDIT"')
  303.     
  304.     rv=close('SE')
  305.     SetProtection("T:SHOWEDIT"||PORT||HANDLE,'srwd')
  306.  
  307.     dopus progress name file info bar abort
  308.     pghandle=result
  309.     if EDIT=0 then do
  310.         dopus progress pghandle title 'Showing files...'
  311.     end
  312.     else do
  313.         dopus progress pghandle title 'Editing files...'
  314.     end
  315.  
  316.     do while cnt < files.count
  317.         dopus progress pghandle name filepart(files.cnt)
  318.         dopus progress pghandle info pathpart(files.cnt)
  319.         dopus progress pghandle bar files.count cnt+1
  320.         dopus progress pghandle file files.count cnt+1
  321.         dopus progress pghandle abort
  322.         if result ~= 0 then return
  323.         If BACKGROUND=0 then Call Unselect
  324.         command WAIT source handle dest handle User4 '"' || makepath(path,files.cnt) || '"'
  325.         cnt=cnt+1
  326.     end
  327.     rv=delete("T:SHOWEDIT"||PORT||HANDLE)
  328.     IF BACKGROUND=0 then Call UnselectLast
  329. end
  330. return
  331.  
  332.  
  333.  
  334. UnselectLast:
  335. if symbol('cpath') = 'VAR' then do
  336.     lister select handle '"' || cpath || '"' 0
  337.     lister refresh handle full
  338. end
  339. return
  340.  
  341.  
  342.  
  343. CleanUp:
  344. if BACKGROUND=1 then lister close handle
  345. dopus progress pghandle off
  346. return
  347.  
  348.  
  349.  
  350. ERROR:
  351. HALT:
  352. IOERR:
  353. SYNTAX:
  354. IF RC ~= 0 THEN DO
  355.  dopus request '"Error in' ProgramName || lf || errortext(rc) lf 'Line' sigl || '"'
  356. END
  357. else do
  358.  dopus request '"Error in' ProgramName
  359. end
  360. BREAK_C:
  361. BREAK_D:
  362. BREAK_E:
  363. BREAK_F:
  364. Call CleanUP
  365. exit 20
  366.